import {AsyncStorage} from 'react-native';
import {NavigationActions,StackActions} from 'react-navigation';
export default class Utils {

    /**
     * 获取用户登录信息
     */
    static async getLoginInfo(){
        try {
           const userInfo = await AsyncStorage.getItem("LoginUserInfo");
           if(userInfo){
               return JSON.parse(userInfo);
           }
        } catch (error) {
            
        }
        return null; 
    }

    static setStorage(key,value){
        return AsyncStorage.setItem(key,JSON.stringify(value));
    }
    static async getStorage(key){
        try {
            const value =  await AsyncStorage.getItem(key);
            if(value){
                return JSON.parse(value);
            }
        } catch (error) {
            
        }
        return null;
      
    }
    static removeStorage(key){
        return AsyncStorage.removeItem(key);
    }
    static navigation(navigation,route,params){
        const resetAction = StackActions.reset({
            index: 0,
            actions: [
                NavigationActions.navigate({routeName:route,params:params}),
            ],
        });
        navigation.dispatch(resetAction)
    }

}